home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / DYN401.ZIP / class / intassoc.c < prev    next >
C/C++ Source or Header  |  1997-04-16  |  5KB  |  172 lines

  1.  
  2.  
  3. /*  Copyright (c) 1993-1996 Algorithms Corporation  */
  4. /*  All rights reserved.  */
  5.  
  6.  
  7.  
  8.  
  9. /*  This file automatically generated by dpp - do not edit  */
  10.  
  11. #define    DPP_STRATEGY    2
  12. #define    DPP_FASTWIDE    0
  13.  
  14.  
  15.  
  16. #line 15 "intassoc.d"
  17. #include <math.h> 
  18.  
  19. #define    CLASS    IntegerAssociation_c
  20. #define    ivType    IntegerAssociation_iv_t
  21.  
  22. #include "generics.h"
  23.  
  24. object    IntegerAssociation_c;
  25.  
  26.  
  27. #line 28 "intassoc.c"
  28. typedef struct  _IntegerAssociation_iv_t  {
  29.     int iKey;
  30.     object iValue;
  31. }    IntegerAssociation_iv_t;
  32.  
  33.  
  34.  
  35. #line 22 "intassoc.d"
  36. cmeth objrtn IntegerAssociation_cm_gNewWithIntObj(object self, int key, object value)
  37.     object assoc; 
  38.     ivType *iv; 
  39.  
  40.     ChkArgNul(value, 3); 
  41.     assoc = oSuper(IntegerAssociation_c, gNew, self)(self); 
  42.     iv = ivPtr(assoc); 
  43.     iv->iKey = key; 
  44.     iv->iValue = value; 
  45.     return assoc; 
  46.  
  47. imeth objrtn IntegerAssociation_im_gDeepCopy(object self)
  48. { IntegerAssociation_iv_t *iv = GetIVs(IntegerAssociation, self);
  49.     object nobj; 
  50.  
  51.     nobj = oSuper(IntegerAssociation_c, gDeepCopy, self)(self); 
  52.     ivPtr(nobj)->iValue = iv->iValue ? gDeepCopy(iv->iValue) : NULL; 
  53.     return nobj; 
  54.  
  55. imeth objrtn IntegerAssociation_im_gValue(object self)
  56. { IntegerAssociation_iv_t *iv = GetIVs(IntegerAssociation, self);
  57.     return iv->iValue; 
  58.  
  59. imeth objrtn IntegerAssociation_im_gChangeValue(object self, object value)
  60. { IntegerAssociation_iv_t *iv = GetIVs(IntegerAssociation, self);
  61.     object ret; 
  62.     ChkArgNul(value, 2); 
  63.     ret = iv->iValue; 
  64.     iv->iValue = value; 
  65.     return ret; 
  66.  
  67. imeth int IntegerAssociation_im_gIntKey(object self)
  68. { IntegerAssociation_iv_t *iv = GetIVs(IntegerAssociation, self);
  69.     return iv->iKey; 
  70.  
  71. imeth objrtn IntegerAssociation_im_gChangeIntKey(object self, int key)
  72. { IntegerAssociation_iv_t *iv = GetIVs(IntegerAssociation, self);
  73.     iv->iKey = key; 
  74.     return self; 
  75.  
  76. imeth objrtn IntegerAssociation_im_gDeepDispose(object self)
  77. { IntegerAssociation_iv_t *iv = GetIVs(IntegerAssociation, self);
  78.     if (iv->iValue) 
  79.         gDeepDispose(iv->iValue); 
  80.     return oSuper(IntegerAssociation_c, gDispose, self)(self); 
  81.  
  82. imeth objrtn IntegerAssociation_im_gStringRepValue(object self)
  83. { IntegerAssociation_iv_t *iv = GetIVs(IntegerAssociation, self);
  84.     object s, t; 
  85.  
  86.     t = iv->iValue ? gStringRepValue(iv->iValue) : gNewWithStr(String, "(null)"); 
  87.     s = vSprintf(String, "( %d, ", iv->iKey); 
  88.     vBuild(s, NULL, t, " )", NULL); 
  89.     gDispose(t); 
  90.     return s; 
  91.  
  92. imeth int IntegerAssociation_im_gHash(object self)
  93. { IntegerAssociation_iv_t *iv = GetIVs(IntegerAssociation, self);
  94.     double t; 
  95.  
  96.     t = .6125423371 * (unsigned) iv->iKey; 
  97.     t = t < 0.0 ? -t : t; 
  98.     return (int) (BIG_INT * (t - floor(t))); 
  99.  
  100. imeth int IntegerAssociation_im_gCompare(object self, object arg)
  101. { IntegerAssociation_iv_t *iv = GetIVs(IntegerAssociation, self);
  102.     int sv, ov; 
  103.  
  104.     ChkArg(arg, 2); 
  105.     if ((sv=iv->iKey) < (ov=gIntKey(arg))) 
  106.         return -1; 
  107.     else if (sv == ov) 
  108.         return 0; 
  109.     else 
  110.         return 1; 
  111.  
  112.  
  113. #line 125 "intassoc.c"
  114.  
  115. objrtn    IntegerAssociation_initialize(void)
  116. {
  117.     static  CRITICALSECTION  cs;
  118.     static  int volatile once = 0;
  119.  
  120.     ENTERCRITICALSECTION(_CI_CS_);
  121.     if (!once) {
  122.         INITIALIZECRITICALSECTION(cs);
  123.         once = 1;
  124.     }
  125.     LEAVECRITICALSECTION(_CI_CS_);
  126.  
  127.     ENTERCRITICALSECTION(cs);
  128.  
  129.     if (IntegerAssociation_c) {
  130.         LEAVECRITICALSECTION(cs);
  131.         return IntegerAssociation_c;
  132.     }
  133.     INHIBIT_THREADER;
  134.     Association_initialize();
  135.     if (IntegerAssociation_c)  {
  136.         ENABLE_THREADER;
  137.         LEAVECRITICALSECTION(cs);
  138.         return IntegerAssociation_c;
  139.     }
  140.     IntegerAssociation_c = gNewClass(Class, "IntegerAssociation", sizeof(IntegerAssociation_iv_t), 0, Association, END);
  141.     cMethodFor(IntegerAssociation, gNewWithIntObj, IntegerAssociation_cm_gNewWithIntObj);
  142.     iMethodFor(IntegerAssociation, gCompare, IntegerAssociation_im_gCompare);
  143.     iMethodFor(IntegerAssociation, gChangeIntKey, IntegerAssociation_im_gChangeIntKey);
  144.     iMethodFor(IntegerAssociation, gValue, IntegerAssociation_im_gValue);
  145.     iMethodFor(IntegerAssociation, gStringRepValue, IntegerAssociation_im_gStringRepValue);
  146.     iMethodFor(IntegerAssociation, gHash, IntegerAssociation_im_gHash);
  147.     iMethodFor(IntegerAssociation, gChangeValue, IntegerAssociation_im_gChangeValue);
  148.     iMethodFor(IntegerAssociation, gDeepDispose, IntegerAssociation_im_gDeepDispose);
  149.     iMethodFor(IntegerAssociation, gDeepCopy, IntegerAssociation_im_gDeepCopy);
  150.     iMethodFor(IntegerAssociation, gIntKey, IntegerAssociation_im_gIntKey);
  151.  
  152.     ENABLE_THREADER;
  153.  
  154.     LEAVECRITICALSECTION(cs);
  155.  
  156.     return IntegerAssociation_c;
  157. }
  158.  
  159.  
  160.  
  161.